package com.example.foodisimportant.Canteens;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.RatingBar;
import android.widget.TextView;

import com.example.foodisimportant.Adapter.MessageAdapter;
import com.example.foodisimportant.Bean.MessageEntity;
import com.example.foodisimportant.R;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

public class DishInformationActivity extends AppCompatActivity {
    private ImageButton mIbbacktohome3;
    private TextView mTvdishname,mTvdishposition;
    private RatingBar mRtrank2;
    private ArrayList<MessageEntity> commentList=new ArrayList<MessageEntity>();
    private RecyclerView mRvComment;
    private MessageAdapter mCommentAdapter;
    Calendar c = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
    String strDate = sdf.format(c.getTime());


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dish);
        mIbbacktohome3=findViewById(R.id.backtohome3);
        mTvdishname=findViewById(R.id.dishname);
        mTvdishposition=findViewById(R.id.tv_position2);
        mRvComment=findViewById(R.id.commentinformation);
        initData();
        initRecyclerView();
        mIbbacktohome3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    /**
     * 模拟数据
     */
    private void initData(){
        for(int i=0;i<10;i++)
        {
            MessageEntity messageEntity=new MessageEntity();
            messageEntity.setName("元和西饼");
            messageEntity.setPreview("用餐提醒");
            messageEntity.setTime(strDate);
            commentList.add(messageEntity);
        }
    }

    /**
     * 对recycleview进行设置
     */
    private void initRecyclerView(){
        //获取RecyclerView
        mRvComment =findViewById(R.id.commentinformation);
        //创建adapter
        mCommentAdapter= new MessageAdapter(DishInformationActivity.this,commentList);
        //给RecyclerView设置adapter
        mRvComment.setAdapter(mCommentAdapter);
        //设置layoutManager,可以设置显示效果，是线性布局、grid布局，还是瀑布流布局
        //参数是：上下文、列表方向（横向还是纵向）、是否倒叙
        mRvComment.setLayoutManager(new LinearLayoutManager(DishInformationActivity.this,LinearLayoutManager.VERTICAL,false));
        //设置item的分割线
        mRvComment.addItemDecoration(new DividerItemDecoration(DishInformationActivity.this,DividerItemDecoration.VERTICAL));
        //RecyclerView中没有item的监听事件，需要自己在适配器中写一个监听事件的接口。参数根据自定义
        mCommentAdapter.setOnItemClickListener(new MessageAdapter.OnItemClickListener() {
            @Override
            public void OnItemClick(View view, MessageEntity data) {
                Intent intent=new Intent(DishInformationActivity.this, MoreCommentsActivity.class);
                startActivity(intent);
            }
        });
    }

}